<?php
session_start();
include("../include/config.inc.php");
include("../include/version.inc.php");
include("../include/tables.inc.php");
include("../include/funktion.inc.php");
include("../include/rights.inc.php");


if(!isset($_SESSION['userid']))
   weiterleitung("index.php");

$rights = $_SESSION['ses_rights'];
$menu = menu($rights);

if(!check($_SERVER['PHP_SELF'],$rights))
  weiterleitung("uebersicht.php");

$was = $_GET['was'];
$fehler = "";

if($was == "export")
   {
   @set_time_limit(0);
   ob_start();
   header("Cache-control: private");
   header("Content-disposition: attachment; filename=emails.txt");
   header("Content-type: text/plain");
   header("Pragma: no-cache");
   header("Expires: 0");

   $abfrage = "SELECT `email`,`name` FROM `$emailsdb` ORDER BY id";
   $ergebnis = mysql_query($abfrage) or die(mysql_error());
   while($row = mysql_fetch_row($ergebnis))
      echo $row[0]."|".$row[1]."\n";


   ob_end_flush();
   exit;
   }
else if($was == "save")
   {
   if(!empty($_FILES['datei']['name']))
      {
      $emails = file($_FILES['datei']['tmp_name']);

      for($i=0;$i<count($emails);$i++)
         {
         $mail = explode("|",$emails[$i]);

         if(trim($mail[0]) != "")
              mysql_query("INSERT INTO `$emailsdb` (`email`, `name`) VALUES ('".trim($mail[0])."', '".trim($mail[1])."')");
         }
      }


   $emails = explode("\n",$_POST['emails']);
   for($i=0;$i<count($emails);$i++)
      {
      $mail = explode("|",$emails[$i]);

      if(trim($mail[0]) != "")
           mysql_query("INSERT INTO `$emailsdb` (`email`, `name`) VALUES ('".trim($mail[0])."', '".trim($mail[1])."')");
      }

   $fehler = "Emails erfolgreich importiert";
   }


?>


<html>
<head>
<title>Clanletter - Admin Bereich</title>
<meta name="author" content="Andavos">
<style type="text/css">
<!--
a:hover { text-decoration:none; }

BODY {

     SCROLLBAR-FACE-COLOR: #4F5271;
     SCROLLBAR-HIGHLIGHT-COLOR: #243D62;
    SCROLLBAR-SHADOW-COLOR: rgb(32,32,32);
    SCROLLBAR-ARROW-COLOR: #ffffff;

}

.anhang {
 font-size: 14px;
 color: #000000;
 background-color: #899FBF;

 border-color: #000000;
 border-top-width :1pt;
 border-right-width : 1px;
 border-bottom-width : 1px;
 border-left-width : 1px;
}

-->
</style>


</head>
<body text="#000000" bgcolor="#D0D0D0" link="#000060" alink="#000060" vlink="#000060">


<table cellpadding="5" cellspacing="2"  bgcolor="black" align="center" width="85%">
<tr>
 <td width="205" valign="top" bgcolor="#899FBF"><a target="_blank" href="http://www.php-einfach.de"><img src="php-einfach.jpg" width="199" height="66" border="0" alt="PHP-Einfach.de"></a> <br>


 <?php echo $menu; ?>


<font size="-1"> <a target="_blank" href="http://www.php-einfach.de">&copy; PHP-Einfach.de Clanletter 2.0</a><br>
 </td>
  <td valign="top" bgcolor="#9BAAC1">
<div align="center"><h2>Automatische Emails</h2></div>

<center><font color="#BD0000"><b><?php echo $fehler; ?></b></font></center>



<form action="?was=save" method="post" target="" enctype="multipart/form-data">
<table bgcolor="#000000" cellpadding="5" cellspacing="1" align="center" width="75%">
<tr bgcolor="#314477">
 <th colspan="2"><font color="#ffffff"><b>Emails exportieren</b></font></td>
</tr>


<tr bgcolor="#FFFFFF">
 <th colspan="2"><a href="?was=export" target="_blank" >Emails exportieren</a></td>
</tr>

<tr bgcolor="#314477">
 <th colspan="2"><font color="#ffffff"><b>Emails importieren</b></font></td>
</tr>



<tr bgcolor="#FFFFFF">
 <td width="125"><b>Datei:</b></td>
 <td><input type="file" name="datei"></input></td>
</tr>

<tr bgcolor="#FFFFFF">
 <td width="125"><b>Weitere Emails:</b></td>
 <td><textarea name="emails" cols="25" rows="5"></textarea></input></td>
</tr>


</tr>
</table>


<br>
<center><input type="Submit" name="" value="Importieren"></center>


</form>

  </td>
</tr>
</table>

</body>
</html>
